# Quick guide

# Pulls the official image. The command pulls the tomcat image with jdk8-corretto tag. The default tag is latest.
# docker pull tomcat:jdk8-corretto

# Runs tomcat image.
# docker run -d --restart always -p 8080:8080 --name=my-tomcat -v d:\my-tomcat-container-home:/home tomcat:jdk8-corretto

# Lists running containers.
# docker ps

# Runs terminal in the container.
# docker exec -it [container-id-can-get-from-last-step] bash

# End of quick guide 

# Use a minimal base image for small size and security.
FROM alpine:3.22.2

# Set working directory early.
WORKDIR /app

# Copy prebuilt binary and other required assets into container.
# (If the app uses config files or static assets, copy them too.)
# This is the preferred for k3s/k8s environment. 
# COPY ./go-gin/family-expense-api/build/ /app/

# Ensure the main binary is executable.
# RUN chmod +x ./cmd/server/family-expense-api

# Uses startup.sh script if you are mapping binary path to host.
# Copies start.sh to root just in case /app is mapped to host.
# Once path is mapped host path overwrites container's.
COPY ./docker/family-expense-golang-alpine/start.sh /
RUN chmod +x /start.sh

# Set environment variables.
ENV GIN_MODE=release \
    OP_ENV_MODE=prod \
    TZ=Asia/Shanghai

# Set timezone properly (using single RUN for fewer layers).
RUN apk add --no-cache tzdata && \
    cp /usr/share/zoneinfo/$TZ /etc/localtime && \
    echo $TZ > /etc/timezone


# Run the binary.
# ENTRYPOINT ["./cmd/server/family-expense-api"]
ENTRYPOINT ["/start.sh"]

# Builds the image.
# The defalut tag is latest. You can define any you need. Example: family-expense-api:1.0
# The -f specifies the Dockerfile path. With this argument we can run build command out of docker file directory. This makes the parent directory of docker file directory the execution context.
# docker build --tag family-expense-api-alpine:3.22.2 -f .\docker\family-expense-golang-alpine\Dockerfile .

# Runs the image.
# The defalut tag is latest. You can define any you need. Example: family-expense-api:1.0
# The --restart always defines the restart policy. Always restart the container if it stops. If it is manually stopped, it is restarted only when Docker daemon restarts or the container itself is manually restarted.
# The -p 8088:8088 defines the port mapping between host and container.
# The -v d:\family-expense-api-home:/home defines mapping directory between host and container.

# Runs container on server with default prod profile.
# docker run -d --restart always -p 8090:8088 --name=family-expense-api-alpine -v /data/family-expense/app:/app family-expense-api-alpine:3.22.2

# Runs container on local still with local profile.
# docker run -d -p 8088:8088 -e OP_ENV_MODE=local --name=family-expense-api-alpine -v D:/Temp/family-expense-app:/app family-expense-api-alpine:3.22.2

# Lists running containers.
# docker ps

# Runs terminal in the container.
# docker exec -it [container-id-can-get-from-last-step] bash

# Saves the image to a local file.
# The defalut tag is latest. You can define any you need. Example: family-expense-api:1.0
# docker save -o d:\family-expense-api-alpine-3.22.2.tar family-expense-api-alpine:3.22.2

# Loads the local image file
# docker load -i d:\family-expense-api-alpine:3.22.2.tar

# Runs MySQL image
# The -e MYSQL_ROOT_PASSWORD=12344321 sets the defalut password for root user.
# The -v d:\family-expense-mysql-home:/var/lib/mysql maps the mysql diectory to the host. This can make sure all database infos remain even this container is deleted.
# docker run --name family-expense-mysql -e MYSQL_ROOT_PASSWORD=12344321 -d -p 3306:3306 -v d:\family-expense-mysql-home:/var/lib/mysql mysql

# More info check on https://docs.docker.com/